package cn.jiahua.hospital.service.impl;

import cn.jiahua.hospital.mapper.DepartmentsMapper;
import cn.jiahua.hospital.pojo.Departments;
import cn.jiahua.hospital.pojo.HdidRelation;
import cn.jiahua.hospital.pojo.Tdepartments;
import cn.jiahua.hospital.service.DepartmentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import java.util.HashMap;

import cn.jiahua.hospital.dto.Page;
import cn.jiahua.hospital.constants.Constants;

@Service
public class DepartmentsServiceImpl implements DepartmentsService {

    @Autowired
    private DepartmentsMapper departmentsMapper;

    @Override
    public Departments getDepartmentsById(Integer DepartmentsId) {
        return departmentsMapper.getDepartmentsById(DepartmentsId);
    }

    @Override
    public List<Departments> getDepartmentsListByMap(Map<String, Object> param) {
        return departmentsMapper.getDepartmentsListByMap(param);
    }

    @Override
    public Integer getDepartmentsCountByMap(Map<String, Object> param) {
        return departmentsMapper.getDepartmentsCountByMap(param);
    }

    @Override
    public Integer qdtxAddDepartments(Departments departments) {
        return departmentsMapper.insertDepartments(departments);
    }

    @Override
    public Integer qdtxModifyDepartments(Departments departments) {
        return departmentsMapper.updateDepartments(departments);
    }

    @Override
    public Integer qdtxDeleteDepartmentsById(Integer id) {
        return departmentsMapper.deleteDepartmentsById(id);
    }

    @Override
    public Integer qdtxBatchDeleteDepartments(String ids) {
        Map<String, List<String>> param = new HashMap<String, List<String>>();
        String[] paramArrays = ids.split(",");
        List<String> idList = new ArrayList<String>();
        for (String temp : paramArrays) {
            idList.add(temp);
        }
        param.put("ids", idList);
        return departmentsMapper.batchDeleteDepartments(param);
    }

    @Override
    public Page<Departments> queryDepartmentsPageByMap(Map<String, Object> param, Integer pageNo, Integer pageSize) {
        Integer total = departmentsMapper.getDepartmentsCountByMap(param);
        pageNo = pageNo == null ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = pageSize == null ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<Departments> departmentsList = departmentsMapper.getDepartmentsListByMap(param);
        page.setList(departmentsList);
        return page;
    }

    @Override
    public List<Tdepartments> getDepartments() {
        return departmentsMapper.getDepartments();
    }

    @Override
    public List<Departments> getDepartments1(Integer hospitalId) {
        return departmentsMapper.getDepartments1(hospitalId);
    }

    @Override
    public List<Departments> departmentsSelectPage(String departmentsName, Integer pageNo, Integer pageSize) {
        return departmentsMapper.departmentsSelectPage(departmentsName, pageNo, pageSize);
    }

    @Override
    public int departmentSelectCount(String departmentsName) {
        return departmentsMapper.departmentSelectCount(departmentsName);
    }

    @Override
    public List<Departments> selectAll(String hospitalId) {
        return departmentsMapper.selectAll(hospitalId);
    }
}